package com.woniuxy.house.provider;

import com.woniuxy.house.entity.Search;
import com.woniuxy.house.entity.User;
import org.apache.ibatis.jdbc.SQL;

/**
 * @author baobo
 * @date 2022-08-27-16:31
 */
public class SearchSqlProvider {
	/**
	 * 多条件查询
	 * @param search
	 * @return
	 */
	public String getByCondition(Search search) {
		return  new SQL() {
			{
				SELECT("*");
				FROM("house_search");
				if(search.getId()!=null){
					WHERE("id=#{id}");
				}
				if(search.getUser()!=null&&search.getUser().getId()!=null){
					WHERE("user_id=#{user.id}");
				}
				if(search.getContent()!=null){
					WHERE("content like concat('%',#{content},'%')");
				}
				if(search.getStartTime()!=null){
					WHERE("time >= #{startTime}");
				}
				if(search.getEndTime()!=null){
					WHERE("time <= #{endTime}");
				}
			}
		}.toString();
	}
	public String getHotSearch(Search search) {
		return  new SQL() {
			{
				SELECT("*");
				FROM("house_search");
				if(search.getId()!=null){
					WHERE("id=#{id}");
				}
				if(search.getUser()!=null&&search.getUser().getId()!=null){
					WHERE("user_id=#{user.id}");
				}
				if(search.getContent()!=null){
					WHERE("content like concat('%',#{content},'%')");
				}
				if(search.getStartTime()!=null){
					WHERE("time >= #{startTime}");
				}
				if(search.getEndTime()!=null){
					WHERE("time <= #{startTime}");
				}
			}
		}.toString();
	}
}